/****************************************************************
*****************************************************************/

#ifndef __JZM_X264_T10_ENC_H__
#define __JZM_X264_T10_ENC_H__

#include <stdint.h>

#include "jzm_vpu.h"

#define SCH_FIFO_DEPTH      16
/************************************************************
 CHN Space Allocation
 ************************************************************/
#define VRAM_DUMMY          (VPU_BASE | 0xFFFFC)

#define VRAM_MAU_RESA       (VPU_BASE | 0xC0000)  //residual address
#define VRAM_MAU_RES_SIZE   (SCH_FIFO_DEPTH*256*4)

#define VRAM_RAWY_BA        (VPU_BASE | 0xF0000)
#define VRAM_RAWC_BA        (VRAM_RAWY_BA + 256)
#define VRAM_RAW_SIZE       (SCH_FIFO_DEPTH*128*4)

#define VRAM_TOPMV_BA       (VRAM_MAU_RESA+VRAM_MAU_RES_SIZE)  //recover address
#define VRAM_TOPPA_BA       (VRAM_TOPMV_BA+VPU_MAX_MB_WIDTH*4)

#define VRAM_MAU_CHN_BASE   (VRAM_TOPPA_BA+VPU_MAX_MB_WIDTH*4)
#define VRAM_MAU_CHN_SIZE   (SCH_FIFO_DEPTH*16*4)
#define VRAM_DBLK_CHN_BASE  (VRAM_MAU_CHN_BASE + VRAM_MAU_CHN_SIZE)
#define VRAM_DBLK_CHN_SIZE  (SCH_FIFO_DEPTH*16*4)
#define VRAM_ME_CHN_BASE    (VRAM_DBLK_CHN_BASE + VRAM_DBLK_CHN_SIZE)
#define VRAM_ME_CHN_SIZE    (SCH_FIFO_DEPTH*8*4)
#define VRAM_SDE_CHN_BASE   (VRAM_ME_CHN_BASE + VRAM_ME_CHN_SIZE)
#define VRAM_SDE_CHN_SIZE   (SCH_FIFO_DEPTH*8*4)

#define VRAM_ME_DSA         DSA_SCH_CH1
#define VRAM_MAU_DEC_SYNA   DSA_SCH_CH2
#define VRAM_DBLK_CHN_SYNA  DSA_SCH_CH3
#define VRAM_SDE_SYNA       DSA_SCH_CH4

#define VRAM_MAU_ENC_SYNA   VRAM_DUMMY
#define VRAM_DBLK_DOUT_SYNA VRAM_DUMMY

#define VRAM_ME_MVPA        (VPU_BASE | REG_EFE_MVRP)

typedef intptr_t paddr_t;

#define __ALN32__ __attribute__ ((aligned(4)))

/*
  _H264E_SliceInfo:
  H264 Encoder Slice Level Information
 */
typedef struct _H264E_SliceInfo {
  /*basic*/
  int     i_csp;
  uint8_t frame_type;
  uint8_t mb_width;
  uint8_t mb_height;
  uint8_t first_mby;
  uint8_t last_mby;  //for multi-slice

  /*vmau scaling list*/
  uint8_t __ALN32__ scaling_list[4][16];

  /*loop filter*/
  uint8_t deblock;      // DBLK CTRL : enable deblock
  uint8_t rotate;       // DBLK CTRL : rotate
  int8_t alpha_c0_offset;   // cavlc use, can find in bs.h
  int8_t beta_offset;

  /*cabac*/   // current hw only use cabac, no cavlc
  uint8_t *state;
  unsigned int bs;          /* encode bitstream start address */
  uint8_t qp;

  /*frame buffer address: all of the buffers should be 256byte aligned!*/
  paddr_t fb[3][2];       /*{curr, ref, raw}{tile_y, tile_c}*/
  /* fb[0] : DBLK output Y/C address
   * fb[1] : MCE reference Y/C address
   * fb[2] : EFE input Y/C buffer address
   */
  paddr_t raw[3];         /*{rawy, rawu, rawv} or {rawy, rawc, N/C}*/
  int stride[2];          /*{stride_y, stride_c}, only used in raster raw*/


  /*descriptor address*/
  paddr_t des_va, des_pa;

  /*TLB address*/
  paddr_t tlba;

}_H264E_SliceInfo;

/*
  H264E_M200_SliceInit(_H264E_SliceInfo *s)
  @param s: slice information structure
 */
void H264E_M200_SliceInit(_H264E_SliceInfo *s);

#endif /*__JZM_H264E_H__*/
